package com.yanfan.modbus.frame;

import com.yanfan.modbus.code.FunctionCode;
import com.yanfan.modbus.exception.ModbusTransportException;
import com.yanfan.modbus.frame.abs.ModbusResponse;
import io.netty.buffer.ByteBuf;


public class WriteCoilsResponse extends ModbusResponse {
    private int startOffset;
    private int numberOfBits;


    public WriteCoilsResponse(int slaveId) throws ModbusTransportException {
        super(slaveId);
    }

    public WriteCoilsResponse(int slaveId, int startOffset, int numberOfBits) throws ModbusTransportException {
        super(slaveId);
        this.startOffset = startOffset;
        this.numberOfBits = numberOfBits;
    }

    @Override
    public byte getFunctionCode() {
        return FunctionCode.WRITE_COILS;
    }


    @Override
    protected void writeResponse(ByteBuf queue) {
        queue.writeShort(startOffset);
        queue.writeShort(numberOfBits);
    }


    @Override
    protected void readResponse(ByteBuf queue) {
        startOffset = queue.readUnsignedShort();
        numberOfBits = queue.readUnsignedShort();
    }

    public int getStartOffset() {
        return startOffset;
    }


    public int getNumberOfBits() {
        return numberOfBits;
    }
}
